package com.whitedust.top20;

import java.util.HashMap;

/**
 * @author A
 * @since 2025/11/3 12:55
 */

public class Top14 {
    //两数之和，采用map来实现
    public int[] twoSum(int[] nums, int target) {
        if (nums == null || nums.length == 0) return null;
        HashMap<Integer, Integer> hash = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (hash.containsKey(target - nums[i])) return new int[]{i, hash.get(target - nums[i])};
            hash.put(nums[i], i);
        }
        return null;
    }
}
